﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KMeansAlgorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            const int k = 2, 
                d = 2;
            double[][] centroids = new double[k][];

            for (int i = 0; i < k; ++i)
            {
                centroids[i] = new double[d];
            }

            centroids[0][0] = 1;
            centroids[0][1] = 1;
            centroids[1][0] = 5;
            centroids[1][1] = 7;

            KMeans km = new KMeans(k, d, centroids);
            
            km.AddData(new double[] { 1.0, 1.0 }, "1");
            km.AddData(new double[] { 1.5, 2.0 }, "2");
            km.AddData(new double[] { 3.0, 4.0 }, "3");
            km.AddData(new double[] { 5.0, 7.0 }, "4");
            km.AddData(new double[] { 3.5, 5.0 }, "5");
            km.AddData(new double[] { 4.5, 5.0 }, "6");
            km.AddData(new double[] { 3.5, 4.5 }, "7");

            var clusterResult = km.Cluster();

            Console.WriteLine("Centroids:");

            foreach (var centroid in clusterResult.Centroids)
            {
                foreach (var dim in centroid)
                {
                    Console.Write(dim + ", ");
                }
                Console.WriteLine();
            }

            Console.WriteLine("Clusters:");

            for (int i = 0; i < k; ++i)
            {
                Console.WriteLine("Cluster " + i + " :");
                var datasInCluster = km.GetDatasInCluster(i);
                
                foreach (var data in datasInCluster)
                {
                    foreach (var dim in data.Data)
                    {
                        Console.Write(dim + ", ");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}
